package mapReduce.demo01_wordCount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCountDriver{

    public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        //4 四个输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //3 三个类
        job.setJarByClass(WordCountDriver.class);
        job.setMapperClass(WordCountMapper.class);
//        job.setReducerClass(WordCountReducer.class);

        //创建一个文件系统的连接
        FileSystem fs = FileSystem.get(conf);

        //设置一个输出路径的公共变量
        Path outputPath = new Path(args[1]);
        //如果文件存在就删除
        if (fs.exists(outputPath)) {
            fs.delete(outputPath,true);
        }

        //2 两个路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,outputPath);

        //1 一次提交任务
        job.waitForCompletion(true);


    }

}
